
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/physics/quantum/gate.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:27:42 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Gates &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../../live.sympy.org/static/live-sphinx.js"></script>
    
    <link rel="shortcut icon" href="../../../_static/sympy-notailtext-favicon.ico"/>
    <link href="gate.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
    <link rel="next" title="Grover’s Algorithm" href="grover.html" />
    <link rel="prev" title="Circuit Plot" href="circuitplot.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="grover.html" title="Grover’s Algorithm"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="circuitplot.html" title="Circuit Plot"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" accesskey="U">Quantum Mechanics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Gates</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.physics.quantum.gate">
<span id="gates"></span><h1>Gates<a class="headerlink" href="#module-sympy.physics.quantum.gate" title="Permalink to this headline">¶</a></h1>
<p>An implementation of gates that act on qubits.</p>
<p>Gates are unitary operators that act on the space of qubits.</p>
<p>Medium Term Todo:</p>
<ul class="simple">
<li><p>Optimize Gate._apply_operators_Qubit to remove the creation of many
intermediate Qubit objects.</p></li>
<li><p>Add commutation relationships to all operators and use this in gate_sort.</p></li>
<li><p>Fix gate_sort and gate_simp.</p></li>
<li><p>Get multi-target UGates plotting properly.</p></li>
<li><p>Get UGate to work with either sympy/numpy matrices and output either
format. This should also use the matrix slots.</p></li>
</ul>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">CGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L301-L481"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.CGate" title="Permalink to this definition">¶</a></dt>
<dd><p>A general unitary gate with control qubits.</p>
<p>A general control gate applies a target gate to a set of targets if all
of the control qubits have a particular values (set by
<code class="docutils literal notranslate"><span class="pre">CGate.control_value</span></code>).</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>label</strong> : tuple</p>
<blockquote>
<div><p>The label in this case has the form (controls, gate), where controls
is a tuple/list of control qubits (as ints) and gate is a <code class="docutils literal notranslate"><span class="pre">Gate</span></code>
instance that is the target operator.</p>
</div></blockquote>
</dd>
</dl>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CGate.controls">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">controls</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.CGate.controls" title="Permalink to this definition">¶</a></dt>
<dd><p>A tuple of control qubits.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CGate.decompose">
<span class="sig-name descname"><span class="pre">decompose</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L392-L409"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.CGate.decompose" title="Permalink to this definition">¶</a></dt>
<dd><p>Decompose the controlled gate into CNOT and single qubits gates.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CGate.eval_controls">
<span class="sig-name descname"><span class="pre">eval_controls</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">qubit</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L388-L390"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.CGate.eval_controls" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True/False to indicate if the controls are satisfied.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CGate.gate">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">gate</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.CGate.gate" title="Permalink to this definition">¶</a></dt>
<dd><p>The non-controlled gate that will be applied to the targets.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CGate.min_qubits">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">min_qubits</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.CGate.min_qubits" title="Permalink to this definition">¶</a></dt>
<dd><p>The minimum number of qubits this gate needs to act on.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CGate.nqubits">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">nqubits</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.CGate.nqubits" title="Permalink to this definition">¶</a></dt>
<dd><p>The total number of qubits this gate acts on.</p>
<p>For controlled gate subclasses this includes both target and control
qubits, so that, for examples the CNOT gate acts on 2 qubits.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CGate.plot_gate">
<span class="sig-name descname"><span class="pre">plot_gate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">circ_plot</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gate_idx</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L436-L454"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.CGate.plot_gate" title="Permalink to this definition">¶</a></dt>
<dd><p>Plot the controlled gate. If <em>simplify_cgate</em> is true, simplify
C-X and C-Z gates into their more familiar forms.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CGate.targets">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">targets</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.CGate.targets" title="Permalink to this definition">¶</a></dt>
<dd><p>A tuple of target qubits.</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CGateS">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">CGateS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L483-L487"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.CGateS" title="Permalink to this definition">¶</a></dt>
<dd><p>Version of CGate that allows gate simplifications.
I.e. cnot looks like an oplus, cphase has dots, etc.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CNOT">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">CNOT</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L845-L956"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.CNOT" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.physics.quantum.gate.CNotGate" title="sympy.physics.quantum.gate.CNotGate"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.physics.quantum.gate.CNotGate</span></code></a></p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CNotGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">CNotGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L845-L956"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.CNotGate" title="Permalink to this definition">¶</a></dt>
<dd><p>Two qubit controlled-NOT.</p>
<p>This gate performs the NOT or X gate on the target qubit if the control
qubits all have the value 1.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>label</strong> : tuple</p>
<blockquote>
<div><p>A tuple of the form (control, target).</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.gate</span> <span class="kn">import</span> <span class="n">CNOT</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.qapply</span> <span class="kn">import</span> <span class="n">qapply</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.qubit</span> <span class="kn">import</span> <span class="n">Qubit</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">CNOT</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">qapply</span><span class="p">(</span><span class="n">c</span><span class="o">*</span><span class="n">Qubit</span><span class="p">(</span><span class="s1">&#39;10&#39;</span><span class="p">))</span> <span class="c1"># note that qubits are indexed from right to left</span>
<span class="go">|11&gt;</span>
</pre></div>
</div>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CNotGate.controls">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">controls</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.CNotGate.controls" title="Permalink to this definition">¶</a></dt>
<dd><p>A tuple of control qubits.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CNotGate.gate">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">gate</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.CNotGate.gate" title="Permalink to this definition">¶</a></dt>
<dd><p>The non-controlled gate that will be applied to the targets.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CNotGate.min_qubits">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">min_qubits</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.CNotGate.min_qubits" title="Permalink to this definition">¶</a></dt>
<dd><p>The minimum number of qubits this gate needs to act on.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.CNotGate.targets">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">targets</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.CNotGate.targets" title="Permalink to this definition">¶</a></dt>
<dd><p>A tuple of target qubits.</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.Gate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">Gate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L119-L298"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.Gate" title="Permalink to this definition">¶</a></dt>
<dd><p>Non-controlled unitary gate operator that acts on qubits.</p>
<p>This is a general abstract gate that needs to be subclassed to do anything
useful.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>label</strong> : tuple, int</p>
<blockquote>
<div><p>A list of the target qubits (as ints) that the gate will apply to.</p>
</div></blockquote>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.Gate.get_target_matrix">
<span class="sig-name descname"><span class="pre">get_target_matrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">format</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'sympy'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L187-L196"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.Gate.get_target_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>The matrix rep. of the target part of the gate.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>format</strong> : str</p>
<blockquote>
<div><p>The format string (‘sympy’,’numpy’, etc.)</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.Gate.min_qubits">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">min_qubits</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.Gate.min_qubits" title="Permalink to this definition">¶</a></dt>
<dd><p>The minimum number of qubits this gate needs to act on.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.Gate.nqubits">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">nqubits</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.Gate.nqubits" title="Permalink to this definition">¶</a></dt>
<dd><p>The total number of qubits this gate acts on.</p>
<p>For controlled gate subclasses this includes both target and control
qubits, so that, for examples the CNOT gate acts on 2 qubits.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.Gate.targets">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">targets</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.Gate.targets" title="Permalink to this definition">¶</a></dt>
<dd><p>A tuple of target qubits.</p>
</dd></dl>

</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.H">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">H</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L632-L680"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.H" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.physics.quantum.gate.HadamardGate" title="sympy.physics.quantum.gate.HadamardGate"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.physics.quantum.gate.HadamardGate</span></code></a></p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.HadamardGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">HadamardGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L632-L680"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.HadamardGate" title="Permalink to this definition">¶</a></dt>
<dd><p>The single qubit Hadamard gate.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>target</strong> : int</p>
<blockquote>
<div><p>The target qubit this gate will apply to.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sqrt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.qubit</span> <span class="kn">import</span> <span class="n">Qubit</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.gate</span> <span class="kn">import</span> <span class="n">HadamardGate</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.qapply</span> <span class="kn">import</span> <span class="n">qapply</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">qapply</span><span class="p">(</span><span class="n">HadamardGate</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span><span class="o">*</span><span class="n">Qubit</span><span class="p">(</span><span class="s1">&#39;1&#39;</span><span class="p">))</span>
<span class="go">sqrt(2)*|0&gt;/2 - sqrt(2)*|1&gt;/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Hadamard on bell state, applied on 2 qubits.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">psi</span> <span class="o">=</span> <span class="mi">1</span><span class="o">/</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">Qubit</span><span class="p">(</span><span class="s1">&#39;00&#39;</span><span class="p">)</span><span class="o">+</span><span class="n">Qubit</span><span class="p">(</span><span class="s1">&#39;11&#39;</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">qapply</span><span class="p">(</span><span class="n">HadamardGate</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span><span class="o">*</span><span class="n">HadamardGate</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="n">psi</span><span class="p">)</span>
<span class="go">sqrt(2)*|00&gt;/2 + sqrt(2)*|11&gt;/2</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.IdentityGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">IdentityGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L607-L629"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.IdentityGate" title="Permalink to this definition">¶</a></dt>
<dd><p>The single qubit identity gate.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>target</strong> : int</p>
<blockquote>
<div><p>The target qubit this gate will apply to.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.OneQubitGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">OneQubitGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L573-L594"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.OneQubitGate" title="Permalink to this definition">¶</a></dt>
<dd><p>A single qubit unitary gate base class.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.Phase">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">Phase</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L775-L800"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.Phase" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.physics.quantum.gate.PhaseGate" title="sympy.physics.quantum.gate.PhaseGate"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.physics.quantum.gate.PhaseGate</span></code></a></p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.PhaseGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">PhaseGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L775-L800"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.PhaseGate" title="Permalink to this definition">¶</a></dt>
<dd><p>The single qubit phase, or S, gate.</p>
<p>This gate rotates the phase of the state by pi/2 if the state is <code class="docutils literal notranslate"><span class="pre">|1&gt;</span></code> and
does nothing if the state is <code class="docutils literal notranslate"><span class="pre">|0&gt;</span></code>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>target</strong> : int</p>
<blockquote>
<div><p>The target qubit this gate will apply to.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.S">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">S</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L775-L800"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.S" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.physics.quantum.gate.PhaseGate" title="sympy.physics.quantum.gate.PhaseGate"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.physics.quantum.gate.PhaseGate</span></code></a></p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.SWAP">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">SWAP</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L959-L1023"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.SWAP" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.physics.quantum.gate.SwapGate" title="sympy.physics.quantum.gate.SwapGate"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.physics.quantum.gate.SwapGate</span></code></a></p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.SwapGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">SwapGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L959-L1023"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.SwapGate" title="Permalink to this definition">¶</a></dt>
<dd><p>Two qubit SWAP gate.</p>
<p>This gate swap the values of the two qubits.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>label</strong> : tuple</p>
<blockquote>
<div><p>A tuple of the form (target1, target2).</p>
</div></blockquote>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.SwapGate.decompose">
<span class="sig-name descname"><span class="pre">decompose</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L979-L984"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.SwapGate.decompose" title="Permalink to this definition">¶</a></dt>
<dd><p>Decompose the SWAP gate into CNOT gates.</p>
</dd></dl>

</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.T">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">T</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L803-L828"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.T" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.physics.quantum.gate.TGate" title="sympy.physics.quantum.gate.TGate"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.physics.quantum.gate.TGate</span></code></a></p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.TGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">TGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L803-L828"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.TGate" title="Permalink to this definition">¶</a></dt>
<dd><p>The single qubit pi/8 gate.</p>
<p>This gate rotates the phase of the state by pi/4 if the state is <code class="docutils literal notranslate"><span class="pre">|1&gt;</span></code> and
does nothing if the state is <code class="docutils literal notranslate"><span class="pre">|0&gt;</span></code>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>target</strong> : int</p>
<blockquote>
<div><p>The target qubit this gate will apply to.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.TwoQubitGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">TwoQubitGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L597-L600"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.TwoQubitGate" title="Permalink to this definition">¶</a></dt>
<dd><p>A two qubit unitary gate base class.</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.UGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">UGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L490-L570"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.UGate" title="Permalink to this definition">¶</a></dt>
<dd><p>General gate specified by a set of targets and a target matrix.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>label</strong> : tuple</p>
<blockquote>
<div><p>A tuple of the form (targets, U), where targets is a tuple of the
target qubits and U is a unitary matrix with dimension of
len(targets).</p>
</div></blockquote>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.UGate.get_target_matrix">
<span class="sig-name descname"><span class="pre">get_target_matrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">format</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'sympy'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L543-L551"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.UGate.get_target_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>The matrix rep. of the target part of the gate.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>format</strong> : str</p>
<blockquote>
<div><p>The format string (‘sympy’,’numpy’, etc.)</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.UGate.targets">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">targets</span></span><a class="headerlink" href="#sympy.physics.quantum.gate.UGate.targets" title="Permalink to this definition">¶</a></dt>
<dd><p>A tuple of target qubits.</p>
</dd></dl>

</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.X">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">X</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L683-L719"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.X" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.physics.quantum.gate.XGate" title="sympy.physics.quantum.gate.XGate"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.physics.quantum.gate.XGate</span></code></a></p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.XGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">XGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L683-L719"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.XGate" title="Permalink to this definition">¶</a></dt>
<dd><p>The single qubit X, or NOT, gate.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>target</strong> : int</p>
<blockquote>
<div><p>The target qubit this gate will apply to.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.Y">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">Y</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L722-L747"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.Y" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.physics.quantum.gate.YGate" title="sympy.physics.quantum.gate.YGate"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.physics.quantum.gate.YGate</span></code></a></p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.YGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">YGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L722-L747"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.YGate" title="Permalink to this definition">¶</a></dt>
<dd><p>The single qubit Y gate.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>target</strong> : int</p>
<blockquote>
<div><p>The target qubit this gate will apply to.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.Z">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">Z</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L750-L772"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.Z" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.physics.quantum.gate.ZGate" title="sympy.physics.quantum.gate.ZGate"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.physics.quantum.gate.ZGate</span></code></a></p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.ZGate">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">ZGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L750-L772"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.ZGate" title="Permalink to this definition">¶</a></dt>
<dd><p>The single qubit Z gate.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>target</strong> : int</p>
<blockquote>
<div><p>The target qubit this gate will apply to.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.gate_simp">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">gate_simp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">circuit</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L1122-L1188"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.gate_simp" title="Permalink to this definition">¶</a></dt>
<dd><p>Simplifies gates symbolically</p>
<p>It first sorts gates using gate_sort. It then applies basic
simplification rules to the circuit, e.g., XGate**2 = Identity</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.gate_sort">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">gate_sort</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">circuit</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L1191-L1240"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.gate_sort" title="Permalink to this definition">¶</a></dt>
<dd><p>Sorts the gates while keeping track of commutation relations</p>
<p>This function uses a bubble sort to rearrange the order of gate
application. Keeps track of Quantum computations special commutation
relations (e.g. things that apply to the same Qubit do not commute with
each other)</p>
<p>circuit is the Mul of gates that are to be sorted.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.normalized">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">normalized</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">normalize</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L89-L103"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.normalized" title="Permalink to this definition">¶</a></dt>
<dd><p>Set flag controlling normalization of Hadamard gates by 1/sqrt(2).</p>
<p>This is a global setting that can be used to simplify the look of various
expressions, by leaving off the leading 1/sqrt(2) of the Hadamard gate.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>normalize</strong> : bool</p>
<blockquote>
<div><p>Should the Hadamard gate include the 1/sqrt(2) normalization factor?
When True, the Hadamard gate will have the 1/sqrt(2). When False, the
Hadamard gate will not have this factor.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.gate.random_circuit">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.gate.</span></span><span class="sig-name descname"><span class="pre">random_circuit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">ngates</span></em>, <em class="sig-param"><span class="pre">nqubits</span></em>, <em class="sig-param"><span class="pre">gate_space=(&lt;class</span> <span class="pre">'sympy.physics.quantum.gate.XGate'&gt;</span></em>, <em class="sig-param"><span class="pre">&lt;class</span> <span class="pre">'sympy.physics.quantum.gate.YGate'&gt;</span></em>, <em class="sig-param"><span class="pre">&lt;class</span> <span class="pre">'sympy.physics.quantum.gate.ZGate'&gt;</span></em>, <em class="sig-param"><span class="pre">&lt;class</span> <span class="pre">'sympy.physics.quantum.gate.PhaseGate'&gt;</span></em>, <em class="sig-param"><span class="pre">&lt;class</span> <span class="pre">'sympy.physics.quantum.gate.TGate'&gt;</span></em>, <em class="sig-param"><span class="pre">&lt;class</span> <span class="pre">'sympy.physics.quantum.gate.HadamardGate'&gt;</span></em>, <em class="sig-param"><span class="pre">&lt;class</span> <span class="pre">'sympy.physics.quantum.gate.CNotGate'&gt;</span></em>, <em class="sig-param"><span class="pre">&lt;class</span> <span class="pre">'sympy.physics.quantum.gate.SwapGate'&gt;)</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/gate.py#L1248-L1276"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.gate.random_circuit" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a random circuit of ngates and nqubits.</p>
<p>This uses an equally weighted sample of (X, Y, Z, S, T, H, CNOT, SWAP)
gates.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>ngates</strong> : int</p>
<blockquote>
<div><p>The number of gates in the circuit.</p>
</div></blockquote>
<p><strong>nqubits</strong> : int</p>
<blockquote>
<div><p>The number of qubits in the circuit.</p>
</div></blockquote>
<p><strong>gate_space</strong> : tuple</p>
<blockquote>
<div><p>A tuple of the gate classes that will be used in the circuit.
Repeating gate classes multiple times in this tuple will increase
the frequency they appear in the random circuit.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../index.html">
              <img class="logo" src="../../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h4>Previous topic</h4>
  <p class="topless"><a href="circuitplot.html"
                        title="previous chapter">Circuit Plot</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="grover.html"
                        title="next chapter">Grover’s Algorithm</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../../_sources/modules/physics/quantum/gate.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="grover.html" title="Grover’s Algorithm"
             >next</a> |</li>
        <li class="right" >
          <a href="circuitplot.html" title="Circuit Plot"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" >Quantum Mechanics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Gates</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/physics/quantum/gate.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:27:43 GMT -->
</html>